package org.example.controller.impl;

import org.example.controller.SaveController;
import org.example.domain.response.ResponseResult;
import org.example.services.impl.SaveServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/save")
public class SaveControllerImpl implements SaveController {

    @Autowired
    private SaveServiceImpl saveService;

    @Override
    @PostMapping("/book/1/{userId}/{bookId}")
    @PreAuthorize("hasAuthority('user:update')")
    public ResponseResult saveUserBook(@PathVariable int userId,@PathVariable int bookId) {
        return saveService.saveUserBook(userId,bookId);
    }

    @Override
    @DeleteMapping("/book/2/{userId}/{bookId}")
    @PreAuthorize("hasAuthority('user:update')")
    public ResponseResult deleteUserBook(@PathVariable int userId,@PathVariable int bookId) {
        return saveService.deleteUserBook(userId,bookId);
    }

    @Override
    @GetMapping("/book/3/{userId}/{currentPage}")
    @PreAuthorize("hasAuthority('user:selectOne')")
    public ResponseResult getUserSaveBooks(@PathVariable int userId,@PathVariable int currentPage) {
        return saveService.getUserSaveBooks(userId, currentPage);
    }

    @Override
    @PostMapping("/discussion/1/{userId}/{discussionId}")
    @PreAuthorize("hasAuthority('user:update')")
    public ResponseResult saveUserDiscussion(@PathVariable int userId,@PathVariable int discussionId) {
        return saveService.saveUserDiscussion(userId, discussionId);
    }

    @Override
    @DeleteMapping("/discussion/2/{userId}/{discussionId}")
    @PreAuthorize("hasAuthority('user:update')")
    public ResponseResult deleteUserDiscussion(@PathVariable int userId,@PathVariable int discussionId) {
        return saveService.deleteUserDiscussion(userId, discussionId);
    }

    @Override
    @GetMapping("/discussion/3/{userId}/{currentPage}")
    @PreAuthorize("hasAuthority('user:selectOne')")
    public ResponseResult getUserDiscussion(@PathVariable int userId,@PathVariable  int currentPage) {
        return saveService.getUserDiscussion(userId, currentPage);
    }
}
